package neusoft.example.com.yuejian06.Model;

import neusoft.example.com.yuejian06.Bean.User;
<<<<<<< HEAD
import neusoft.example.com.yuejian06.PublicIp;
=======
import neusoft.example.com.yuejian06.PublicActivity;
>>>>>>> 933bae1c0e2db0b5f4e6e201bd36bb77e66599e2
import neusoft.example.com.yuejian06.RetrofitListener;
import neusoft.example.com.yuejian06.Service.UserService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class LoginModel {
    private Retrofit retrofit;
<<<<<<< HEAD
    private UserService service;
=======
    private LoginService service;
    private PublicActivity publicActivity;

>>>>>>> 933bae1c0e2db0b5f4e6e201bd36bb77e66599e2
    public LoginModel() {
        publicActivity= new PublicActivity();
        retrofit=new Retrofit.Builder()
<<<<<<< HEAD
                .baseUrl(PublicIp.ip+"api/index/")
=======
                .baseUrl(publicActivity.getIp()+"api/index/")
>>>>>>> 933bae1c0e2db0b5f4e6e201bd36bb77e66599e2
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        service = retrofit.create(UserService.class);
    }

    public void login(String user_tel, String user_password, final RetrofitListener<User> listener) {
        Call<User> call = service.login(user_tel, user_password);
        call.enqueue(new Callback<User>() {
            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                if(response.isSuccessful() && response!=null){
                    listener.onResponse(response.body());
                }else{
                    listener.onFail("服务器炸了！");//
                }
            }

            @Override
            public void onFailure(Call<User> call, Throwable t) {
                listener .onFail(t.toString());
            }
        });
    }
}
